//拖拽api
import interact from "interactjs";
export default {
  inserted(el, binding, vnode, oldVnode) {
    const position = { x: 0, y: 0 };
    interact(el).draggable({
      ignoreFrom: binding.value.ignore ? binding.value.ignore : ".ignore",
      modifiers: [
        interact.modifiers.restrictRect({
          restriction: binding.value.pardom,
        }),
      ],
      listeners: {
        start(event) {
          binding.value.cb && binding.value.cb();
        },
        move(event) {
          position.x += event.dx / binding.value.scale;
          position.y += event.dy / binding.value.scale;
          event.target.style.transform = `translate(${position.x}px, ${position.y}px)`;
        },
      },
    });
  },
  unbind(el, binding, vnode, oldVnode) {
    interact(el).unset();
  },
};
